﻿<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"  x:Class="MvvmMessaging.CustomerListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:my="clr-namespace:MvvmMessaging"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="250"
    >
    <UserControl.Resources>
        <my:CustomerListViewModel x:Key="vm" />
    </UserControl.Resources>
    
    <StackPanel x:Name="LayoutRoot" Background="White">
        <ListBox Name="customerListBox"  Height="100"
                 DataContext="{StaticResource vm}"
                 ItemsSource="{Binding Path=Customers}"
                 SelectedItem="{Binding Path=SelectedCustomer, Mode=TwoWay}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=CustomerName}" Padding="5,5,0,5" />
                        <TextBlock Text=":" Padding="5,5,0,5" />
                        <TextBlock Text="{Binding Path=Orders}" Padding="5,5,0,5" FontWeight="Bold" />
                        <TextBlock Text="Orders" Padding="5" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Increase Orders" Height="30" Width="100" Margin="5">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <ei:CallMethodAction 
                            TargetObject="{Binding Source={StaticResource vm}}"
                            MethodName="IncreaseOrders"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button><toolkit:WrapPanel />
        <TextBlock Text="{Binding Source={StaticResource vm}, Path=MessageText}" 
                       FontSize="14" FontWeight="Bold" Foreground="Blue" 
                       HorizontalAlignment="Center" Visibility="{Binding Path=MessageVisibility}" 
                       TextWrapping="Wrap" />
    </StackPanel>
</UserControl>
